﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Ch.Admin.Bfs.Sms.Sdmx.Extension.CodeBook.Dlg
{
    public partial class DlgSaveBook : Form
    {
        public string Activity
        {
            get
            {
                string[] arr = comboBoxActivity.SelectedItem.ToString().Split('-');
                return arr[0].Trim();
            }
        }

        public string FullId
        {
            get
            {
                return ucAgencyRef.Text.Trim() + "+" + textBoxID.Text.Trim() + "+" + textBoxVersion.Text.Trim();
            }
        }

        public DlgSaveBook(List<string>Activities, string bookIdentity)
        {
            InitializeComponent();
            comboBoxActivity.Items.AddRange(Activities.ToArray());

            textBoxID.Text = string.Empty;
            textBoxVersion.Text = "1.0";
            ucAgencyRef.Text = "CH1_SMS";

            string[] arr = bookIdentity.Split('+');
            if (arr.Length == 3)
            {
                textBoxID.Text = arr[1];
                textBoxVersion.Text = arr[2];
                ucAgencyRef.Text = arr[0];
            }
        }

        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            // Check filled
            if (comboBoxActivity.SelectedIndex < 0 ||
                ucAgencyRef.Text.Trim().Length == 0 || textBoxVersion.Text.Trim().Length == 0 ||
                textBoxID.Text.Trim().Length == 0)
            {
                MessageBox.Show(this, "Please complete book identification...", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
                DialogResult = DialogResult.OK;
        }
    }
}
